package com.crm.service.impl.couponManager;

import com.crm.dao.mapper.couponManager.CouponIssuedMapper;
import com.crm.dao.mapper.customMapper.couponCustomManager.CouponIssuedCustomMapper;
import com.crm.dao.mapper.customMapper.orderManagerCustomMapper.CustomerProductOrderCustomMapper;
import com.crm.model.entity.couponManager.CouponIssued;
import com.crm.model.entity.couponManager.CouponIssuedExample;
import com.crm.model.qo.orderManager.CustomerProductOrderQO;
import com.crm.model.vo.couponManager.CouponIssuedVO;
import com.crm.model.vo.orderManager.CustomerProductOrderVO;
import com.crm.service.couponManager.CouponIssuedDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author renshaorong
 * @Date 2021/11/9
 */
@Service
public class CouponIssuedDbServiceImpl implements CouponIssuedDbService {

    @Autowired
    private CouponIssuedCustomMapper couponIssuedCustomMapper;

    @Autowired
    private CouponIssuedMapper couponIssuedMapper;

    @Autowired
    private CustomerProductOrderCustomMapper customerProductOrderCustomMapper;

    @Override
    public List<CouponIssuedVO> selectCouponIssuedPageList(CouponIssued couponIssued, String order) {
        return couponIssuedCustomMapper.selectCouponIssuedPageList(couponIssued,order);
    }

    @Override
    public boolean insertBatch(List<CouponIssued> couponIssuedList) {
        return couponIssuedCustomMapper.insertBatch(couponIssuedList) == couponIssuedList.size();
    }

    @Override
    public List<CustomerProductOrderVO> selectCustomerProductOrder(CustomerProductOrderQO customerProductOrderQO, String order) {
        return customerProductOrderCustomMapper.selectCustomerProductOrder(customerProductOrderQO,order);
    }

    @Override
    public CouponIssued selectByCouponIdAndCustomerId(String couponId, String customerId) {
        CouponIssuedExample couponIssuedExample = new CouponIssuedExample();
        CouponIssuedExample.Criteria criteria = couponIssuedExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andChsCustomerCouponIdEqualTo(couponId);
        List<CouponIssued> couponIssuedList = couponIssuedMapper.selectByExample(couponIssuedExample);
        if( couponIssuedList.size() > 0 ){
            return couponIssuedMapper.selectByExample(couponIssuedExample).get(0);
        }
        return null;
    }

    @Override
    public Boolean updateCouponIssuedById(CouponIssued couponIssued) {
        int num = couponIssuedMapper.updateByPrimaryKeySelective(couponIssued);
        if(num>0){
            return null;
        }else{
            return false;
        }
    }
}
